import { Component, OnInit, Output, EventEmitter } from '@angular/core';

import { RemoveTableService } from 'app/public/serve/remove-table/remove-table.service';
import { HintsService } from 'app/public/serve/hints/hints.service';

import { ipRuleUrl } from '../ip-rule.url';

@Component({
  selector: 'ip-rule-delete',
  templateUrl: './ip-rule-delete.component.html',
  styleUrls: ['./ip-rule-delete.component.css']
})
export class IpRuleDeleteComponent implements OnInit {

  @Output() delete = new EventEmitter<void>();

  constructor(
    private request: RemoveTableService,
    private hintsService: HintsService
  ) {}

  ngOnInit() {
  }

  /**
   * 删除
   */
  _delete() {  

    this.request
        .confirmRemove('ipRuleId', ipRuleUrl.delete)
        .then(res=>{
          if (res.result_code == '0000') {
            this.delete.emit();
          }
          this.hintsService._operationHints(res.message, res.result_code);
          return
        })
        .catch(err=> {
          this.hintsService._operationHints('error', 'error');
          return
        })
  }

}
